﻿@using VirtualPress.Infrastructure.Entities.Entity
@using VirtualPress.Tool.Framework;
@using VirtualPress.Infrastructure.Entities.Enum;
@using VirtualPress.Infrastructure.Entities.JSONModel
@{
    Periodical journal = ViewBag.Journal;
    ViewBag.Title = "专审分配 -- " + journal.Name;
    Layout = "/Areas/WorkSpace/Views/Shared/_WorkSpace.cshtml";
}
@section head{
<link type="text/css" rel="Stylesheet" href="/content/css/select2.css" />
}
<div id="content-header">
    <h1>
        稿件分配</h1>
</div>
<div id="breadcrumb">
    <a href="/WorkSpace/console/index" class="tip-bottom"><i class="icon-home"></i>起始页</a> <a href="/WorkSpace/Press/TobeDistributed">
        待分配稿件</a> <a href="javascript:" class="current">稿件分配</a>
</div>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-align-justify"></i></span>
                    <h5>
                        稿件分配</h5>
                </div>
                <div class="widget-content nopadding">
                    @{Article article = ViewBag.Article;
                      List<ArticleAuthor> author = ViewBag.Author;
                      List<Appendix> attachment = ViewBag.Attachment;
                      }
                    <form class="form-horizontal" method="post" 
                        action="/workspace/console/distribution" name="basic_validate" >
                    <input type="hidden" id="hidexperts" name="experts" />
                    <input type="hidden" name="ArticleId" value="@article.Id" />
                    <div class="control-group">
                        <label class="control-label">
                            稿件标题:</label>
                        <div class="controls">
                            <label class="controls-label">
                                @article.Title</label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            英文标题:</label>
                        <div class="controls">
                            <label class="controls-label">
                                @article.Title_EN</label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            作者:</label>
                        <div class="controls">
                            <label class="controls-label">
                                @for (int i=0, len =author.Count;i<len;i++)
                                { 
                                    @Html.Raw(author[i].AuthorName)
                                    if (i != len - 1)
                                    {
                                        @Html.Raw("， "); 
                                    }
                                }
                                </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            稿件范围:</label>
                        <div class="controls">
                            <label class="controls-label">
                                @article.GJFW
                                </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            稿件文件:</label>
                        <div class="controls">
                            <ul>
                                @if (attachment != null && attachment.Any())
                                {
                                    foreach (var att in attachment)
                                    { 
                                    <li><a target="_blank" href="/download?token=@EncodeByBase64.Encode(new { id = att.Id, type = 9 }.ToJson())" title="点击下载">
                                        <i class="icon-file icon-large"></i>
                                        @att.FileName;</a>
                                        <span style="color:#999;font-style: italic;padding-left:25px;">@att.CreateTime.ToString("yyyy-MM-dd")</span>
                                    </li>
                                    }
                                }
                             </ul>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            审稿完成时间 （天）:</label>
                        <div class="controls">
                            <input id="txtFinishDate" onblur="changefinishdate(this)" style="width:180px !important;" type="text" name="FinishDate" value="@journal.DefaultExamineDay" /> 
                            &nbsp;&nbsp;&nbsp;于 <span id="boxfinishdate">@(DateTime.Now.AddDays(journal.DefaultExamineDay).ToString("yyyy-MM-dd"))</span> 审稿完成
                        </div>
                    </div>
                    <div id="expertbox" class="control-group">
                        <label class="control-label">
                            选择专家:</label>
                        <div class="controls">
                            <select id="sltexperts" multiple>
                        @{
                            List<ExpertAndJobModel> list = ViewBag.ExpertList;
                            if(list != null && list.Any())
                            {
                                foreach(var item in list)
                                {
                                    <option value="@item.ExpertUserName">@item.ExpertName @item.JobCount</option>
                                }
                            }
                            }
                            </select> 
                            <a href="/workspace/console/counsellor">添加编委专家</a>
                            <span class="help-block">1、B表示编辑部专家 2、Z表示外聘专家 3、数字代表专家当前在审稿件数</span>
                        </div>
                    </div>
                    <div class="form-actions">
                        <a href="/workspace/console/article?group=1" class="btn">返 回</a>
                        <input type="submit" class="btn btn-primary" value="分 派" />
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@section tail{
    <script type="text/javascript" src="/scripts/select2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#sltexperts').select2();
            $('#likarticle').addClass('active open');
            $('form').submit(function () {
                var finishDate = $('#txtFinishDate');
                if (!/^\d+$/.test(finishDate.val())) {
                    finishDate.parent().parent().parent().addClass('error');
                    finishDate.parent().parent().append(
                            $('<span generated="true" class="help-inline" style="">输入有误.</span>')
                        );
                    return false;
                }

                var choose = $('.chooseitem').length;
                if (choose == 0) {
                    $('#expertbox').addClass('error');
                    $('#expertbox').children('.controls:eq(0)').append(
                            $('<span generated="true" class="help-inline" style="">required.</span>')
                        );
                    return false;
                }
                else {
                    $('#expertbox').removeClass('error');
                    $('#expertbox').children('.controls:eq(0)').children('.help-inline:eq(0)').remove();
                }
                var sid = "";
                $('.chooseitem').each(function () {
                    var ci = $(this).children('div').text();
                    $('#sltexperts').children('option').each(function () {
                        if (ci == $(this).text()) {
                            sid += $(this).val() + ';';
                        }
                    });
                });
                $('#hidexperts').val(sid);
            });
        });
        function changefinishdate(sender) {
            var day = $(sender).val();
            if (parseInt(day, 10) > 0) {
                day = parseInt(day, 10);
                var myhelper = new dateHelper();
                var newdate = myhelper.AddDays(new Date(), day);
                $('#boxfinishdate').text(myhelper.Format(newdate, "yyyy-MM-dd"));
            }
        }
    </script>
}
